﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace paint
{
    public partial class FrmMain : Form
    {
        private Graphics graphics; //图片对象
        public FrmMain()
        {
            InitializeComponent();
            CenterToScreen();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            
            
        }

        private void btnDraw_Click(object sender, EventArgs e)
        {
            graphics = pictureBox1.CreateGraphics(); //获取pictureBox1的图片对象
            graphics.DrawLine(Pens.Red, 10, 10, 50, 10);
            Pen blackPen = Pens.Black;
            Point[] point = new Point[2];
            point[0].X = 10;
            point[0].Y = 10;
            point[1].X = 60;
            point[1].Y = 60;
            Rectangle rect = new Rectangle(50, 20, 40, 60);
            //graphics用黑笔对象把两点用线连接（也就是画一条先，两点为起止点）
            graphics.DrawLine(blackPen, point[0], point[1]);
            graphics.DrawRectangle(blackPen, rect);
            graphics.DrawEllipse(blackPen, rect);
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            
            Color clearColor;
            clearColor = Color.White;
            try
            {
                graphics.Clear(clearColor);
                //pictureBox1.Image = null;//这个也行
            }
            catch
            {
                MessageBox.Show("请先绘图");
            }
        }

        private void FrmMain_Activated(object sender, EventArgs e)
        {
            
        }
    }
}
